//
//  DYWCommonController.swift
//  sinaWeibo
//
//  Created by 董艳武 on 16/2/5.
//  Copyright © 2016年 董艳武. All rights reserved.
//

import UIKit
// 创建公用的父控制器
// 成为代理对象  
// 遵守协议
// 实现代理方法
class DYWCommonController: UITableViewController,visitorViewDelegate {
    

    // 是否加载用户访问  
    lazy var isVisitor:Bool = true
    
    // 视图属性
    var visitorView : DYWVisitorView?
    
    override func loadView() {
//    let accountModel = DYWAccountModel.getUserInfo()
//    print(accountModel!.expires_date)
        isVisitor = (DYWOauthViewModel.sharedInstance.accountModel?.access_token != nil) ? false:true
//        print(isVisitor)
        if isVisitor {
            visitorView = DYWVisitorView()
            view = visitorView
            visitorView!.imgViewAnimating()
            // 设置代理
            visitorView?.delegate = self
            setNav()
            return
        } else {
            super.loadView()
            
        }
    }
    
   // 实现代理方法
    func didClickRegistButton() {
        print(self.classForCoder,"注册")
        // 跳转到 nav 
        // 1、创建视图控制器
        let Oauth = DYWOauthController()
        // 2、嵌入到一个导航栏控制器
        let nav = UINavigationController(rootViewController: Oauth)
        // 3、跳转
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func didClickLoginButton() {
        print(self.classForCoder,"登陆")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        reloadInputViews()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    
    private func setNav () {
//        view  = UIView()
//        view.backgroundColor = UIColor.orangeColor()
        
        
//        navigationController?.navigationBar.tintColor = UIColor.orangeColor()
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "didClickRegistButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "didClickLoginButton")
        
        
        
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

}
